/**
 * @author liuxl
 */
Ext.ux.VisitLogsPanel = function(){
	if (!checkPermission()) {
		return false;
	}
	var desktop = MyDesktop.getDesktop();
        var win = desktop.getWindow('visit_logs-grid-win');
        if (!win) {
			
			  var sm = new Ext.grid.CheckboxSelectionModel();
            var _jsonReader = null;
            //工作日志管理
           
            _jsonReader = new Ext.data.JsonReader({
                root: 'results',
                //successProperty : 'success'
                totalProperty: 'totalCount'
            }, [{
                name: 'code',
                mapping: 'code'
            },{
                name: 'categoryName',
                mapping: 'categoryName'
            }, {
                name: 'count',
                mapping: 'count'
            }]);
  
            var ds = null;
            //工作日志管理
       
                ds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/admin/visitLogs.jhtml?method=getVisitLogs'
                    }),
                    reader: _jsonReader
                });
            
          
            
            //定义列头信息
            var cm = null;
            //工作日志管理
          
                cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),sm,{
                    header: "类型",
                    width: 50,
                    sortable: true,
                    dataIndex: 'code'
                    //renderer:cover_image
                    //editor: new Ext.form.TextField()
                },{
                    header: "主题",
                    width: 100,
                    sortable: true,
                    dataIndex: 'categoryName'
                }, {
                    header: "访问量",
                    width: 100,
                    sortable: true,
                    dataIndex: 'count'
                }]);
            /**
             * 搜索
             */
            var searchEntity = function() {
            	//alert( start_time.getRawValue() );
            	ds.baseParams.searcyType = p_comb.getValue();
            	ds.baseParams.name = title_text.getValue();
            	ds.baseParams.startTime = start_time.getRawValue();
            	ds.baseParams.endTime = end_time.getRawValue();
            	ds.load({params : {start : 0,limit : 20}
            	});
            }  ;  
            	 
            	 var btn_search_entity = new Ext.Button({
            	text : '查询',
            	iconCls : 'icon-search',
            	handler : searchEntity
            });
 
                 var ds_user_select = new Ext.data.Store({
                     proxy: new Ext.data.HttpProxy({
                         url: '/admin/visitLogs.jhtml?method=getStatsType'
                     }),
                     reader: new Ext.data.JsonReader({
                         root: 'results'
                     }, [{
                         name: 'name'
                     }, {
                         name: 'desc',
                         type: 'string'
                     }])
                 }); 
            	 
            	 var p_label= new Ext.form.Label({
            		 
            		 text:'查询类型:'
            	 });
            	 
            	 var p_comb = new Ext.form.ComboBox({
                  	  name: 'name',
                  	width : 100,
                      valueField: 'name',
	                    hiddenName: 'name',
	                    displayField: 'desc',
	                    mode: 'remote',
                      store: ds_user_select,
                      typeAhead: true,
                      triggerAction: 'all',
                      emptyText: '请选择...',
                      selectOnFocus: true,
						 allowBlank: false,
                      blankText: '不能为空'
                  }); 
                 
                 
            	 var title_label= new Ext.form.Label({
					 	text:'关键字:'
					 });
					
					 var title_text = new Ext.form.TextField({
						name : 'title_text',
						width : 100,
						emptyText : '请输入关键词!',
						listeners : {
							'specialkey' : function(field, e) {
								if (e.getKey() == Ext.EventObject.ENTER) {
									searchEntity();
								}
							}
						}
					});
            	 
            	 /**
            	  * 开始时间 start 
            	  */
            	 var start_label= new Ext.form.Label({
            		 
            		 text:'开始时间:'
            	 });
            	 
            	 var start_time = new Ext.form.DateField({
                 	name : 'start_time',
                 	 format:'Y-m-d',
                 	emptyText : '请选择时间!'
                 	
                 });   
            	 /**
            	  * 开始时间 end 
            	  */
            	 
            	 /**
            	  * 结束时间 start 
            	  */
            	 var end_label= new Ext.form.Label({
            		 
            		 text:'结束时间:'
            	 });
            	 
            	 var end_time = new Ext.form.DateField({
                 	name : 'end_time',
                 	 format:'Y-m-d',
                 	emptyText : '请选择时间!'
                 	
                 });   
            	 /**
            	  * 结束时间 end 
            	  */
           
            var grid = null;
            //日志管理

                grid = new Ext.grid.GridPanel({
                    cm: cm,
                    sm: sm,
                    border: false,
                    loadMask: { // 加载数据时出险遮罩时状态条上呈现的等待信息
                        msg: "数据加载中，请稍等..."
                    },
                    store: ds,
                    viewConfig: {
                        forceFit: true // 自动调整每列的宽度
                    },
                    //autoExpandColumn:'company',
                    //添加分页工具条
                    bbar: new Ext.PagingToolbar({
                        pageSize: 20,
                        store: ds,
                        displayInfo: true
                    }),
                    tbar: [p_label,p_comb,'&nbsp&nbsp',title_label,title_text,'&nbsp&nbsp',start_label,start_time,'&nbsp&nbsp',end_label,end_time,btn_search_entity,'-',{
                        text: '查看日详细',
                        tooltip: '查看日详细内容',
                        iconCls: 'add',
                        handler: function(){
							
							   var rows = grid.getSelectionModel().getSelections();// 返回值为 Record 数组 
                            if (rows.length == 0) {
                            	getAlertMessage("警告","最少选择一条信息，进行操作!",Ext.MessageBox.WARNING);
                            }
                            else {
								var lId = rows[0].get("categoryName");
								var code = rows[0].get("code");
								if(lId=='总访问量'){
									var url='/admin/visitLogStat_all.jsp?searchType='+code+'&startTime='+start_time.getRawValue()+'&endTime='+end_time.getRawValue();
                                	window.open(url,'newwindow','height=400,width=1024,top=100,left=100,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
								}else{
									var url='/admin/visitLogStat_day.jsp?lId='+lId+'&searchType='+code+'&startTime='+start_time.getRawValue()+'&endTime='+end_time.getRawValue();
                                	window.open(url,'newwindow','height=400,width=1024,top=100,left=100,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no');
								}
					   return ;
                            } // 弹出对话框警告 
                        }
                    }]
                })
            
            
            //创建表格end
            //////////////////////////////////////////
            win = desktop.createWindow({
                id: 'visit_logs-grid-win',
                title: 'Wap访问日志统计分析',
                width: 840,
                height: 580,
                iconCls: 'icon-grid',
                shim: false,
                animCollapse: false,
                constrainHeader: true,
                
                layout: 'fit',
                items: grid
            
            });
                grid.store.load({
                    params: {
                        start: 0,
                        limit: 20
                    },
    				callback: listError
                });
           // grid.render();
        }
        win.show();
}
